/**
 * Created by dr2009 on 2017/2/21.
 */
const path = require('path');
const webpack = require("webpack");
const webpackMerge = require('webpack-merge');
const commonConfig = require('./base.js');

module.exports = function (env) {
    return webpackMerge(commonConfig(), {
        entry: {
            main: [
                'react-hot-loader/patch',
                // activate HMR for React

                'webpack-dev-server/client?http://0.0.0.0:4000',
                // bundle the client for webpack-dev-server
                // and connect to the provided endpoint

                'webpack/hot/only-dev-server',
                // bundle the client for hot reloading
                // only- means to only hot reload for successful updates
            ]
        },
        output: {
            filename: '[name].js',
            // the output bundle

            path: path.resolve(__dirname, '../dist'),

            // publicPath: './src'
            // necessary for HMR to know where to load the hot update chunks
        },
        devServer: {
            hot: true,
            // enable HMR on the server

            host: '0.0.0.0',

            port: 4000,

            contentBase: path.resolve(__dirname, '../../server/public'),
            // match the output path

            publicPath: '/'
            // match the output `publicPath`
        },
        plugins: [
            new webpack.HotModuleReplacementPlugin(),
            // enable HMR globally

            new webpack.NamedModulesPlugin(),
            // prints more readable module names in the browser console on HMR updates

            new webpack.DefinePlugin({
                'process.env.NODE_ENV': JSON.stringify('production'),
                'XSite_ENV': JSON.stringify('env'), // test | gray | prod
            })
        ]
    })
};